//
//  SAEventClient.m
//  GameFrame
//
//  Created by Hiroshi Nomura on 2014/05/24.
//  Copyright (c) 2014年 Hiroshi Nomura. All rights reserved.
//

#import "SAEventClient.h"

@implementation SAEventClient

-(id)initWithEventQueueSize:(NSInteger)capacity
{
    if (self = [super init])
    {
        eventQueue = [[NSMutableArray alloc] initWithCapacity:capacity];
    }
    
    return self;
}

-(void)processEventMessage
{
    if (eventQueue.count > 0)
    {
        for (int i=0; i<eventQueue.count; i++)
        {
            SAEventMessage* message = (__bridge SAEventMessage*)[eventQueue objectAtIndex:0];
            //Process Event Message
            NSLog(@"This event id is %s",message->messageId);
            [eventQueue removeObjectAtIndex:0];
        }
    }
}

-(void)handlEvent:(id)sender message:(SAEventMessage*)message
{
    //TODO: Check Message
    [eventQueue addObject:(__bridge id)(message)];
}

-(void)sendEventMessage:(SAEventMessage*)message
{
    
}

-(void)registerEventListener:(SAEventType)type
{
    //It's possible for concurrent processes to access the same resource.
    //This method must synchronize other processes.
}

-(void)unregisterEventListener:(SAEventType)type
{
    //It's possible for concurrent processes to access the same resource.
    //This method must synchronize other processes.
}

@end
